package com.hexacta.hrs.sandbox.pr.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.hexacta.hrs.sandbox.pr.data.Dao;
import com.hexacta.hrs.sandbox.pr.model.Person;
import com.hexacta.hrs.sandbox.pr.model.Profile;

public class PersonServiceImpl implements PersonService {

	@Autowired
	private Dao dao;

	public Dao getDao() {
		return dao;
	}

	public void setDao(Dao dao) {
		this.dao = dao;
	}

	public Long addPerson(Person person) {
		return this.getDao().add(person);
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<Person> findPersonByName(String name) {
		return (List<Person>) this.getDao().findByName(Person.class, name);
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<Person> listAll() {
		return (List<Person>) this.getDao().listAll(Person.class);
	}

	@Override
	public void removePerson(Person person) {
		this.getDao().remove(person);
	}

	@Override
	public Long addPerson(String name, String password, List<Profile> profiles) {
		Person person = new Person();
		person.setName(name);
		person.setPassword(password);
		person.setProfiles(profiles);
		
		return this.addPerson(person);
	}
}